package cn.bas.controller;

import cn.bas.constants.ServiceExceptionEnum;
import cn.bas.core.exception.ServiceException;
import cn.bas.core.vo.CommonResult;
import cn.bas.vo.UserVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
@RequestMapping("/users")
public class UserController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @GetMapping("/get")
    public UserVo get(@RequestParam("id")Integer id){
        return new UserVo().setId(id).setUsername(UUID.randomUUID().toString());
    }

    @GetMapping("/get2")
    public CommonResult<UserVo> get2(@RequestParam("id") Integer id){
        return CommonResult.success(new UserVo().setId(id).setUsername(UUID.randomUUID().toString()));
    }

    @GetMapping("/exception-01")
    public UserVo exception1(){
        throw new NullPointerException("空指针异常");
    }

    @GetMapping("/exception-02")
    public UserVo exception2(){
        throw new ServiceException(ServiceExceptionEnum.USER_NOT_FOUND);
    }

    @GetMapping("/do_something")
    public void dosomething(){
        logger.info("[dosomething]");
    }



    @GetMapping("/current_user")
    public UserVo currentUser() {
        logger.info("[currentUser]");
        return new UserVo().setId(10).setUsername(UUID.randomUUID().toString());
    }

    @GetMapping("/exception-03")
    public void exception03() {
        logger.info("[exception03]");
        throw new ServiceException(ServiceExceptionEnum.USER_NOT_FOUND);
    }

}
